This repository was archived by the owner on Apr 14, 2022. It is now read-only.
Fixed BeanPostProcessor detection. #9
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi,
While playing around with
FunctionalConfiguration
I've discovered thatBeanPostProcessor
instances registered in the context viabean()
DSL method do not processes the beans as they ought to.The minimal example of such broken configuration is demonstrated below.
What we expect here is that String will be injected into the
AutowireSubject
asautowiredMember
. Unfortunately it is not true.I couldn't resist the temptation and investigated this problem a little bit. The issue is that
FunctionalConfiguration#bean
method registers theFunction0Wrapper
instance which is responsible for creating the actualBeanPostProcessor
object. HoweverAbstractBeanFactory#isFactoryBean
method cannot recognize thatFunction0Wrapper#apply
method returnsBeanPostProcessor
instance because the return type of the latter method is parameterized as<T>
(i.e. returnsObject
for the reflection API).I definitely don't feel like Spring internals expert, but the solution that seems reasonable for me is to recognize on the
FunctionalGenericBeanDefinition
level if the wrapped function returnsBeanPostProcessor
. If so, thenFunctionalGenericBeanDefinition
should be created with the special version ofFunction0Wrapper#apply
method called (let's say)Function0Wrapper#applyAsBeanPostProcessor
. The latter factory method would wrapFunction0<BeanPostProcessor>
instances and explicitly defineBeanPostProcessor
return type. IfFunction0Wrapper
factory method defined onFunctionalGenericBeanDefinition
has return type ofBeanPostProcessor
, thenAbstractBeanFactory#isFactoryBean
works like a charm. AndAbstractBeanFactory#isFactoryBean
method working properly resolves the issue, asAbstractApplicationContext#registerBeanPostProcessors
can recognize that instance return byFunction0Wrapper
is aBeanPostProcessor
.The pull request contains both fix and test case for it.
Best regards.